package inesv.proto;

import com.google.protobuf.InvalidProtocolBufferException;

import inesv.proto.AddressBookProtos.AddressBook;
import inesv.proto.AddressBookProtos.AddressBook.Builder;
import inesv.proto.AddressBookProtos.Person;
import inesv.proto.AddressBookProtos.Person.PhoneNumber;
import inesv.proto.AddressBookProtos.Person.PhoneType;

public class protoTest {

	public static void main(String[] args) throws InvalidProtocolBufferException {
        
		Person person = Person.newBuilder()
				               .setId(1)
				               .setName("lin")
				               .setEmail("245393886@qq.com")
				               .addPhones(PhoneNumber.newBuilder().setNumber("15218612811")
				            		                              .setType(PhoneType.WORK))
				               .build();
		AddressBook addressBook = AddressBook.newBuilder()
				                         .addPeople(person)
				                         .build();
		//序列化之前
		System.out.println("序列化之前  "+addressBook.toString());
		
		//序列化
		byte[] addressBook_se = addressBook.toByteArray();
		System.out.println("序列化  " + addressBook_se);
		
		
		//反序列化
		AddressBook AddressBook_de = AddressBook.parseFrom(addressBook_se);
		System.out.println("反序列化 " + AddressBook_de);
		
		
	}

}
